--  ---------------------------------------------------------------------------
--  @File: errors.adb
--
--  @Project: LiberAda
--  @Version: 1.0
--  @Created: 2009-09-23
--  @Author:  Markus Knauß, Julian Trischler
--
--  @Description:
--    For a detailed description of this package (@see errors.ads).
--  @Implementation:
--    Handling with error messages is realized here.
--
--  @Modifications:
--    +2012-01-13 BM,AZ: Added Help Message system.
--    +2011-04-23 JT: Corrected termination with failure exit code and printing
--      error message to StdErr instead of StdOut.
--    +2009-09-23 MK: Initial release
--
--  ---------------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Command_Line;

package body Errors is

   package ATIO renames Ada.Text_IO;

   No_Help_Printed : Boolean := True;

   --  ------------------------------------------------------------------------
   --  @Procedure: Print_Error
   procedure Print_Error (Msg : in String) is
   begin
      if No_Help_Printed then
         Print_Help;
         No_Help_Printed := False;
      end if;
      ATIO.Put_Line (Ada.Text_IO.Standard_Error, "Error: " & Msg);
      Ada.Command_Line.Set_Exit_Status (Ada.Command_Line.Failure);
   end Print_Error;

   --  ------------------------------------------------------------------------
   --  @Procedure: Print_Help
   procedure Print_Help is
   begin
      ATIO.New_Line;
      ATIO.Put_Line ("Usage:");
      ATIO.Put_Line (Formatter.Format ("%1C80",HELP_TEXT_PARAMS));
      ATIO.New_Line;
      ATIO.Put_Line ("Examples:");
      ATIO.Put_Line (Formatter.Format ("%2C80",HELP_TEXT_PARAMS));
      ATIO.New_Line;
      ATIO.Put_Line ("Parameters:");
      ATIO.New_Line;
      --   -i parameter help text
      ATIO.Put (Formatter.Format ("%3C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("Files and directories to include. This is a semicolon");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("separated list of files and directories.");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("For each file HTML documentation is generated,");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("for all source files in a directory documentation");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("is generated.");
      ATIO.New_Line;
      -- -r parameter help text
      ATIO.Put (Formatter.Format ("%4C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("Recurse through the given directories.");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("This indicates whether subdirectories" &
                     " should be included or not.");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("If this parameter is not present," &
                     " subdirectories are not included.");
      ATIO.New_Line;
      --  -o parameter help text
      ATIO.Put (Formatter.Format ("%5C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("Directory to which the generated documentation" &
                     " is written.");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("Defaults to ./ if parameter not specified");
      ATIO.New_Line;
      --  -ext parameter help text
      ATIO.Put (Formatter.Format ("%6C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("Extensions of source files that are parsed. This" &
                     " is a list of");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("extensions, seperated by spaces. If no extensions are" &
                     " given,");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("the default Ada file extensions .adb and .ads are");
      ATIO.Put (Formatter.Format ("%0C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("used if this parameter isn't specified.");
      ATIO.New_Line;
      --  -v parameter help text
      ATIO.Put (Formatter.Format ("%7C10",HELP_TEXT_PARAMS));
      ATIO.Put_Line ("Whether to use verbose output or not. Default is off");
      ATIO.New_Line;
   end Print_Help;

end Errors;
